<template>
  <div id="app">
    <h2>第四个练习</h2>
    <table class="tb">
      <tr>
        <th>欢迎光临vue开发的收银系统——水果店</th>
      </tr>
      <tr>
        <td>
          <b>苹果{{ price }}￥/斤,折扣是{{ count }}折</b>
        </td>
      </tr>
      <tr>
        <td>
          请输入您要购买的斤数 &nbsp;<input
            type="text"
            v-model.number.trim="num"
          />
        </td>
      </tr>
      <tr>
        <td><button @click="pay">老板买单~</button></td>
      </tr>
      <tr>
        <td>
          <span>总价是{{ total }}元</span>&nbsp;
          <span>折扣后{{ countPay }}元</span>&nbsp;
          <span>省了{{ less }}元</span>&nbsp;
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: 1,
      price: 10,
      count: 8,
      total: 10,
      countPay: 8,
      less: 2,
    };
  },

  methods: {
    pay() {
      this.total = this.price * this.num;
      this.countPay = this.total * this.count * 0.1;
      this.less = this.total - this.countPay;
    },
  },

  // computed: {
  //   total() {
  //     return this.price * this.num;
  //   },
  //   countPay() {
  //     return this.total * this.count * 0.1;
  //   },
  //   less() {
  //     return this.total - this.countPay;
  //   },
  // },
};
</script>

<style scoped>
#app {
  width: 600px;
  margin: 10px auto;
}

.tb {
  border-collapse: collapse;
  width: 100%;
}

.tb th {
  background-color: pink;
  color: white;
}

.tb td,
.tb th {
  padding: 5px;
  border: 1px solid black;
  text-align: center;
}

.add {
  padding: 5px;
  border: 1px solid black;
  margin-bottom: 10px;
}
</style>